package org.xinjiang.data.migration.hainan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xinjiang.data.migration.common.response.PageInfo;
import org.xinjiang.data.migration.common.response.Param;
import org.xinjiang.data.migration.common.utils.query.Pages;
import org.xinjiang.data.migration.common.utils.query.Queries;
import org.xinjiang.data.migration.hainan.convert.JzdxConvert;
import org.xinjiang.data.migration.hainan.dto.req.JzdxQueryDTO;
import org.xinjiang.data.migration.hainan.dto.res.JzdxResultDTO;
import org.xinjiang.data.migration.hainan.entity.JzdxEntity;
import org.xinjiang.data.migration.hainan.mapper.JzdxMapper;
import org.xinjiang.data.migration.hainan.service.IJzdxService;

@Service
public class JzdxServiceImpl extends ServiceImpl<JzdxMapper, JzdxEntity> implements IJzdxService {
    @Autowired
    private JzdxConvert jzdxConvert;

    @Override
    public PageInfo<JzdxResultDTO> pageList(Param pageable, JzdxQueryDTO dto) {
        IPage<JzdxEntity> page = this.page(Pages.page(pageable), wrapper(dto));
        return Pages.convert(page, jzdxConvert::convert);
    }

    private LambdaQueryWrapper<JzdxEntity> wrapper(JzdxQueryDTO query) {
        LambdaQueryWrapper<JzdxEntity> wrapper = Queries.lambda();
        Queries.accept(query.getId(), v -> wrapper.eq(JzdxEntity::getId, v));
        Queries.accept(query.getSqjzrybh(), v -> wrapper.eq(JzdxEntity::getSqjzrybh, v));
        Queries.accept(query.getZt(), v -> wrapper.eq(JzdxEntity::getZt, v));
        return wrapper;
    }
}
